/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function (s) {
  const data = {
    I: 1,
    IV: 4,
    V: 5,
    IX: 9,
    X: 10,
    XL: 40,
    L: 50,
    XC: 90,
    C: 100,
    CD: 400,
    D: 500,
    CM: 900,
    M: 1000
  }
  let right = 1
  let num = 0
  while (right <= s.length) {
    if (data[s[right - 1] + s[right]]) {
      num += data[s[right - 1] + s[right]]
      right += 2
    } else {
      num += data[s[right - 1]]
      right += 1
    }
  }
  return num
}
console.log(romanToInt('MCMXCIV'))
